package com.scqkxx.gamebox.utils;

import android.content.Context;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVOSCloud;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.FindCallback;

import java.util.List;

/**
 * Created by zsx on 2018/8/22.
 */

public class PushGTClientUtils {
    public static AVObject GTCObject;//通知数据

    public static void setGTClient(Context context, String cid) {
        AVOSCloud.setDebugLogEnabled(true);
        // 初始化应用 Id 和 应用 Key，您可以在应用设置菜单里找到这些信息
        AVOSCloud.initialize(context, "3G47drEAaXtmQas7U4WxEmx4-gzGzoHsz",
                "x3cl6OYR2mC6dDQsW0dMeceJ");
        AVQuery<AVObject> avQuery = new AVQuery<>("A_DxtGTClient");
        avQuery.whereEqualTo("cid", cid);
        avQuery.findInBackground(new FindCallback<AVObject>() {
            @Override
            public void done(List<AVObject> list, AVException e) {
                if (e == null) {
                    if (list == null || list.size() == 0) {
                        AVObject avObject = new AVObject("A_DxtGTClient");
                        avObject.put("cid", cid);
                        if (AVUser.getCurrentUser() != null) {
                            avObject.put("userObjectId", AVUser.getCurrentUser().getObjectId());
                        }
                        avObject.saveInBackground();
                        GTCObject = avObject;
                    } else {
                        AVObject avObject = list.get(0);
                        if (AVUser.getCurrentUser() != null) {
                            avObject.put("userObjectId", AVUser.getCurrentUser().getObjectId());
                        }
                        avObject.saveInBackground();
                        GTCObject = avObject;
                    }
                }
            }
        });
    }

}